import request, { get, post, put, del } from '@/utils/request'
import { Loading, Message } from 'element-ui'
const defaultApi = (apiName) => {
  return {
    list: (params) => get(`/${apiName}/list`, params),
    page: (params) => get(`/${apiName}`, params),
    read: (id) => get(`/${apiName}/` + id),
    create: (id, data) => post(`/${apiName}`, {}, data),
    update: (id, data) => put(`/${apiName}/` + id, {}, { ...data, create_time: undefined, id: undefined }),
    delete: (id) => del(`/${apiName}/` + id)
  }
}
export const http = {
  user: defaultApi('user'),
  banner: defaultApi('banner'),
  config: defaultApi('config'),
  group: defaultApi('group'),
  vote: defaultApi('vote'),
}

export const uploadFile = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/upload/file',
    method: 'post',
    data: formData
  })
}

export const uploadFileCos = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/upload/filecos',
    method: 'post',
    data: formData
  })
}
